//
//  RootTabBarViewController.m
//  DLTravels
//
//  Created by mac1012 on 2016/12/13.
//  Copyright © 2016年 DianlE. All rights reserved.
//

#import "RootTabBarViewController.h"
#import "RDVTabBarItem.h"
#import "RDVTabBar.h"
#import "BaseNavigationController.h"
#import "WeatherViewController.h"
#import "TravelsViewController.h"
#import "SettingViewController.h"

@interface RootTabBarViewController (){
   
}



@end

@implementation RootTabBarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
   
    
    [self setupViewController];
    
    // Do any additional setup after loading the view.
}

- (UIStatusBarStyle )preferredStatusBarStyle{
    
    return UIStatusBarStyleLightContent;
    
}

- (void)setupViewController{

    
    SettingViewController *settingVC = [[SettingViewController alloc] init];
    settingVC.title = @"设置";
    BaseNavigationController *settingNav = [[BaseNavigationController alloc] initWithRootViewController:settingVC];
    
    TravelsViewController *travelsVC = [[TravelsViewController alloc] init];
    travelsVC.title = @"游记";
    BaseNavigationController *travelNav = [[BaseNavigationController alloc] initWithRootViewController:travelsVC];
    
    WeatherViewController *weatherVC = [[WeatherViewController alloc] init];
    weatherVC.title = @"天气";
    BaseNavigationController *weatherNav = [[BaseNavigationController alloc] initWithRootViewController:weatherVC];
    
    
    
    
    NSArray *viewControllers = @[weatherNav,travelNav,settingNav];
    
    [self setViewControllers:viewControllers];
    [self customizeTabBarForController];
    
    
}

- (void)customizeTabBarForController{
    
    UIImage *backgroudImage = [UIImage imageWithColor:kColorTbaBG];
    NSArray *tabBarItemTitles = @[@"天气",@"游记",@"设置"];
    NSArray *tabBarItemImages = @[@"Weather",@"Travels",@"Setting"];
    NSInteger index = 0;
    for(RDVTabBarItem *item in self.tabBar.items){
        
        NSString *selectImageName = [NSString stringWithFormat:@"Tabbar_Select%@",tabBarItemImages[index]];
        NSString *unSelectImageName = [NSString stringWithFormat:@"Tabbar_unSelect%@",tabBarItemImages[index]];
        
        UIImage *selectedImage = [UIImage imageNamed:selectImageName];
        UIImage *unselectedImage = [UIImage imageNamed:unSelectImageName];
        
        item.titlePositionAdjustment = UIOffsetMake(0, 3);
        
        
        NSDictionary *tabBarTitleUnselectedDic = @{NSForegroundColorAttributeName:[UIColor colorWithHexString:@"dbdbdb"],NSFontAttributeName:[UIFont systemFontOfSize:10]};
        
         NSDictionary *tabBarTitleSelectedDic = @{NSForegroundColorAttributeName:[UIColor whiteColor],NSFontAttributeName:[UIFont systemFontOfSize:12]};
        
        item.selectedTitleAttributes = tabBarTitleSelectedDic;
        item.unselectedTitleAttributes = tabBarTitleUnselectedDic;
        
        
        [item setTitle:tabBarItemTitles[index]];
        
        [item setBackgroundSelectedImage:backgroudImage withUnselectedImage:backgroudImage];
        [item setFinishedSelectedImage:selectedImage withFinishedUnselectedImage:unselectedImage];
        
        index ++;
    }
    
    [self.tabBar addLineUp:YES andDown:NO andColor:kColorCCC];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
